package cn.com.miao.lynx.common.base.model;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Test
 *
 * @title: Test
 * @description:
 * @author: dengmiao
 * @create: 2020-05-09 18:34
 **/
public class Test {

    public static void main(String[] args) {
        final List<Tree> meta = new ArrayList<>();
        Tree a = new Tree();
        a.setId(1);a.setParentId(0);a.setName("a");
        meta.add(a);
        Tree b = new Tree();
        b.setId(2);b.setParentId(1);b.setName("b");
        meta.add(b);
        Tree c = new Tree();
        c.setId(3);c.setParentId(1);c.setName("c");
        meta.add(c);
        Tree d = new Tree();
        d.setId(4);d.setParentId(2);d.setName("d");
        meta.add(d);
        Tree e = new Tree();
        e.setId(5);e.setParentId(2);e.setName("e");
        meta.add(e);
        Tree f = new Tree();
        f.setId(6);f.setParentId(3);f.setName("f");
        meta.add(f);

        System.out.println(meta);

        List<Tree> trees = TreeModel.toChildren(meta);
        System.out.println(trees);

        Double i = Double.NaN;
        Double j = Double.NaN;
        System.out.println(i > j || i <= j);

        Integer[] source = new Integer[]{1,2,3,4,5,6,7,8};
        ArrayList<Integer> target = new ArrayList<>(Arrays.asList(source));
        target.removeIf(item -> item % 2 == 0);
        System.err.println(target);
        //Integer[] result = removeOddOrEven(source, false);
    }

    public static Integer[] removeEven(Integer[] source, boolean removeOdd) {
        if (null == source || source.length == 0) {
            return source;
        }
        List<Integer> resultList = new ArrayList<Integer>();
        for (int e : source) {
            boolean remove = (removeOdd && e % 2 != 0) || (!removeOdd && e % 2 == 0);
            if (!remove) {
                resultList.add(e);
            }
        }
        int length = resultList.size();
        Integer[] result = new Integer[length];
        Integer[] toArray = resultList.toArray(new Integer[length]);
        for (int i = 0; i < length; i++) {
            result[i] = toArray[i];
        }
        return result;
    }

}

class Tree extends TreeModel<Tree, Integer> {

    private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "{" +
                "\"id\":" + this.getId() +
                ", \"parentId\":" + this.getParentId() +
                ", \"name\":\"" + name + "\"" +
                ", \"children\":" + this.getChildren() +
                '}';
    }
}
